//
// Created by 11510 on 2024/6/22.
//
#include <iostream>
#include <memory>
using namespace std;

void test1(){
    auto_ptr<int> ap1(new int(6));
    auto_ptr<int> ap2(ap1);


    printf("ap2 = %d\n", *ap2);
//    已经移交管理权，此处段错误
    printf("ap1 = %d\n", *ap1);

}

/*
 * double free
 */
void test2(){
    int * a = new int(8);
    unique_ptr<int> up1(a);
    unique_ptr<int> up2(a);
    cout << *up2 << endl;
    cout << *up1 << endl;

}

/*
 * double free
 */
void test3(){
    unique_ptr<int> up(new int(5));
    unique_ptr<int> up2(new int(4));
//让两个unique_ptr对象托管了同一片空间
    up.reset(up2.get());
}

/**
 * double free
 */
void test4(){
    int * a = new int(8);
    shared_ptr<int> sp(a);
    shared_ptr<int> sp2(a);
}


/**
 * double free
 */
void test5(){
    shared_ptr<int> sp(new int(1));
    shared_ptr<int> sp2(new int(8));
    sp.reset(sp2.get());
}



int main(void){
    test5();
    return 0;
}